package NC64_二叉搜索树与双向链表;


class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}



public class Solution {
    private TreeNode head = null;
    private TreeNode last = null;

    public TreeNode Convert(TreeNode pRootOfTree) {
        if (pRootOfTree == null){
            return null;
        }

        inorder(pRootOfTree);

        return head;
    }

    private void inorder(TreeNode node) {
        if (node == null){
            return;
        }

        inorder(node.left);
        if (last != null){
             last.right = node;
        }else {
            head = node;
        }
        node.left = last;
        last = node;

        inorder(node.right);

    }
}
